mui.init();

mui.plusReady(function () {
	var self = plus.webview.currentWebview();
	var forget_mob_code = self.code;
	var mobile  = self.mobile;

    var oldPwd = document.getElementById('oldPwd');
    var newPwd = document.getElementById('newPwd');
    var submitBtn = document.getElementById('submitBtn');
   
    submitBtn.addEventListener('tap',function(){
	   	if(oldPwd.value.length == 0){
	   		plus.ui.toast('旧密码不能为空');
	   		return false;
	   	}else if(newPwd.value.length == 0){
	   		plus.ui.toast('新密码不能为空');
	   		return false;
	   	}else if(oldPwd.value !== newPwd.value){
	   		plus.ui.toast('新旧密码不一致');
	   		oldPwd.value = '';
	   		newPwd.value = '';
	   		return false;
	   	}else{
            plus.nativeUI.showWaiting('密码重置中...');
            var api_host = plus.storage.getItem('HOST_URL');
            var oldP = oldPwd.value;
            var newP = newPwd.value;
            mui.ajax({
                url:api_host+'/api/linxuan/user/forgetpwd',
                data:{'mobile':mobile,'repwd':oldP,'newpwd':newP,'verify':forget_mob_code},
                dataType:'json',
                type:'post',
                timeout:5000,
                success:function(msg){
                    if(msg.code == 1){
                        plus.nativeUI.closeWaiting();
                        mui.toast(msg.msg,{ duration:'1500', type:'div'});
                        setTimeout(function () {
                            mui.openWindow({
                                url: "login.html",
                                id:'loginHtml',
                            })
                        },2000)
                    }else{
                        plus.nativeUI.closeWaiting();
                        mui.toast(msg.msg,{ duration:'2000', type:'div'});
                    }
                },
                error:function(xhr,type,errorThrown){
                    plus.nativeUI.closeWaiting();
                    mui.toast('重置密码出错，请联系客服！',{ duration:'2000', type:'div'});
                }
            });
		}

    });
    
});